/*
 * AjustarSOM.java
 *
 * Created on 7 de junio de 2008, 18:48
 */
package View;

import Control.InterfaceControl;
import java.util.Vector;
import javax.swing.JOptionPane;
import matrices.centro.Clase;

/**
 *
 * @author  Jose Antonio Gonzalez, Ambrin Chaudhary
 */
public class AjustarSOM extends javax.swing.JFrame implements InterfaceVista {

    private InterfaceControl controlador;

    /** Creates new form AjustarSOM */
    public AjustarSOM() {
        initComponents();
        this.setTitle("Parámetros de ajuste");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        btn_aceptar = new javax.swing.JButton();
        jAlfaInicial = new javax.swing.JTextField();
        jAlfaFinal = new javax.swing.JTextField();
        jKMax = new javax.swing.JTextField();
        btn_cancelar = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jT = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Introduzca los parámetros del ajuste:");

        jLabel2.setText("Alfa inicial");

        jLabel3.setText("Alfa final");

        jLabel4.setText("K máxima");

        btn_aceptar.setText("Aceptar");
        btn_aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_aceptarActionPerformed(evt);
            }
        });

        btn_cancelar.setText("Cancelar");
        btn_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_cancelarActionPerformed(evt);
            }
        });

        jLabel5.setText("T");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(39, 39, 39)
                        .add(btn_aceptar)
                        .add(44, 44, 44)
                        .add(btn_cancelar))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(35, 35, 35)
                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel3)
                            .add(jLabel2)
                            .add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel4))
                        .add(42, 42, 42)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jKMax)
                            .add(jT)
                            .add(jAlfaInicial)
                            .add(jAlfaFinal, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE))))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jLabel1)
                .add(18, 18, 18)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(jAlfaInicial, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(jAlfaFinal, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(jT, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(jKMax, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 49, Short.MAX_VALUE)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btn_aceptar)
                    .add(btn_cancelar))
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(31, Short.MAX_VALUE)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(58, 58, 58))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(21, 21, 21)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btn_aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_aceptarActionPerformed

    try {

        //compruebo que introduce todos los parámetros
        if (this.jAlfaInicial.getText().equalsIgnoreCase("") || this.jAlfaFinal.getText().equalsIgnoreCase("") ||
                this.jT.getText().equalsIgnoreCase("") || this.jKMax.getText().equalsIgnoreCase("")) {
            this.muestraError("Debe especificar el valor de todos los parámetros");
        } else {



            //obtengo los parámetros introducidos y los paso a tipo Double
            Double alfa_inicial = Double.valueOf(this.jAlfaInicial.getText());
            Double alfa_final = Double.valueOf(this.jAlfaFinal.getText());
            Double t = Double.valueOf(this.jT.getText());
            Double k_max = Double.valueOf(this.jKMax.getText());



            //creo el vector de parametros [alfa,alfa inicial, alfa final, kmax, T, omega, epsilon]
            Vector<Double> params = new Vector<Double>();
            params.add(0.0);
            params.add(alfa_inicial);
            params.add(alfa_final);
            params.add(k_max);
            params.add(t);
            params.add(0.0);
            params.add(0.0);

            //pasarle los datos al controlador
            this.controlador.ajustar(params);

            //cerrar la ventana:
            this.setVisible(false);
        }

    } catch (Exception e) {
        this.muestraError("Parámetro no válido");
    }

}//GEN-LAST:event_btn_aceptarActionPerformed

private void btn_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_cancelarActionPerformed

    this.setVisible(false);
}//GEN-LAST:event_btn_cancelarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_aceptar;
    private javax.swing.JButton btn_cancelar;
    private javax.swing.JTextField jAlfaFinal;
    private javax.swing.JTextField jAlfaInicial;
    private javax.swing.JTextField jKMax;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jT;
    // End of variables declaration//GEN-END:variables

    public void registerControl(InterfaceControl controlador) {
        this.controlador = controlador;
    }

    public void muestraError(String mensajeError) {
        JOptionPane.showMessageDialog(this,
                mensajeError, "ERROR: ",
                JOptionPane.ERROR_MESSAGE);
    }

    public void muestraResultado(Vector<Clase> datos) {
        //en principio no debe mostrar nada
    }

    public void mostrarVentana() {
        this.setVisible(true);
    }
}
